Skip to content

gh-144650: support Vectorcall for _decimal.Decimal's - #158207

Closed
skirpichev wants to merge 11 commits into
python:mainfrom
skirpichev:decimal-ac/144650
Closed

skirpichev wants to merge 11 commits into
python:mainfrom
skirpichev:decimal-ac/144650

Conversation

@skirpichev

@skirpichev skirpichev commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

This shows almost no effect on "official" pyperformance benchmarks (see python/pyperformance#473):

Benchmarks with tag 'decimal':
==============================

decimal_pi: Mean +- std dev: [ref] 1.97 sec +- 0.01 sec -> [patch] 1.95 sec +- 0.02 sec: 1.01x faster

Benchmark hidden because not significant (1): decimal_factorial

Geometric mean: 1.01x faster

But on micro-benchmarks:

Benchmark ref patch
Decimal(0) 620 ns 537 ns: 1.15x faster
Decimal(123) 621 ns 540 ns: 1.15x faster
Decimal('123') 788 ns 677 ns: 1.16x faster
Geometric mean (ref) 1.16x faster

(Default ./configure options, gcc 14.2)

Details
# bench.py
import pyperf
from decimal import Decimal

runner = pyperf.Runner()
for x in [0, 123, '123']:
    h = f"Decimal({x!r})"
    runner.bench_func(h, Decimal, x)

@skirpichev skirpichev changed the title Support Vectorcall for _decimal.Decimal's gh-144650: support Vectorcall for _decimal.Decimal's Sep 26, 2026
@cmaloney

Copy link
Copy Markdown
Contributor

#157968 may help with the build failures (changes how the assert works which should make it better across module boundaries)

@skirpichev

Copy link
Copy Markdown
Member Author

Thanks. The Decimal is only possible candidate being a heap type in the stdlib. That was worked before in skirpichev#18

@skirpichev
skirpichev marked this pull request as draft September 26, 2026 03:02
@skirpichev skirpichev self-assigned this Sep 26, 2026
@cmaloney

Copy link
Copy Markdown
Contributor

👍 hopefully will get more of these landed soon :). str and list still need some special work for stable performance over the change which I'm still root causing (likely compiler inlining vs. existing hand inlining). If there are ways I can help enable / particular edge cases you find let me know. Otherwise planning to make PRs as I have time + performance results for existing cases across the codebase (int, float, str, list, bytes, bytearray, bool, filter, set, frozenset are on my radar).

cmaloney and others added 3 commits September 26, 2026 06:31
Convert the static types to heap types. Move empty init vectorcall to
share with existing no-arg __init__ case. Add support for no-argument
vectorcall so the no-arg __init__ cases actually work (rather than
adding an arg). Produce the same error string as the PyArg helpers do.

The vectorcall types no longer have a C address for the generated
`Py_Is` so instead compare the slot function instead. This drops the
requirement that a class using vectorcall declare a type object.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

(cherry-picked from python#157968)
@skirpichev
skirpichev marked this pull request as ready for review September 26, 2026 03:41
@skirpichev skirpichev removed their assignment Oct 2, 2026
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 6, 2026
@skirpichev

skirpichev commented Oct 8, 2026 •

Copy link
Copy Markdown
Member Author

CC @vstinner, does it make sense for you?

Edit: N.B., this depends on #157968.

# Conflicts:
#	Modules/clinic/_testclinic.c.h
@skirpichev skirpichev closed this Oct 17, 2026
@skirpichev
skirpichev deleted the decimal-ac/144650 branch October 17, 2026 03:07
@vstinner

Copy link
Copy Markdown
Member

Did you close it because you consider that it's not worth it?

@skirpichev

Copy link
Copy Markdown
Member Author

I think it still worth it, assuming micro-benchmarks. It's for free, anyway.

But it's on top of #157968. If you are ok, I'll reopen this one that pr (or some its alternative) will be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants